package com.example.textviewactivity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;

import com.example.textviewactivity.pojo.User;

import java.io.Serializable;

public class CheckBoxActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    CheckBox smoking,dreak,scalding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_box);
        smoking=findViewById(R.id.smoking);
        dreak=findViewById(R.id.dreak);
        scalding=findViewById(R.id.scalding);
        smoking.setOnCheckedChangeListener(this);
        dreak.setOnCheckedChangeListener(this);
        scalding.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        switch (compoundButton.getId()){
            case R.id.smoking:
                if (b){
                    Toast.makeText(this, "您选中了抽烟", Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(this, "您取消选中抽烟", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.dreak:
                if (b){
                    Toast.makeText(this, "您选中了喝酒", Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(this, "您取消选中喝酒", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.scalding:
                if (b){
                    Toast.makeText(this, "您选中了烫头", Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(this, "您取消选中烫头", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }


}
